package com.boost.cipher.utils;

import java.math.BigDecimal;

public class DecToHexRate {

    public static void main(String[] args) {
        System.out.println(scale(0.25));
    }

    public static String scale(double grayPercent) {
        if (grayPercent <= 0) {
            return "000";
        }
        if (grayPercent >= 100) {
            return "ggg";
        }
        BigDecimal rate = new BigDecimal(String.valueOf(grayPercent));
        int r = rate.multiply(new BigDecimal("100")).intValue();

        int arg = Math.round((float) r * 4096 / 10000);
        StringBuilder res = new StringBuilder(Integer.toHexString(arg));
        if (res.length() > 3) {
            return "ggg";
        }
        return res.toString();
    }

}
